package snail.tiger.com.tigerplayer.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import snail.tiger.com.tigerplayer.R;
import snail.tiger.com.tigerplayer.tools.AudioPlayerUtil;

public class TurnView extends android.support.v7.widget.AppCompatTextView {

    private int mDefaultColor;

    private Context mContext;

    public TurnView(Context context) {
        super(context);
        init(context, null);
    }

    public TurnView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public TurnView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        mContext = context;

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TurnView);
        mDefaultColor = typedArray.getColor(R.styleable.TurnView_defaultColor, Color.parseColor("#ffffff"));
        setBackgroundColor(mDefaultColor);
        typedArray.recycle();
    }

    public void setFocus(boolean isFocus) {
        if (isFocus) {
            AudioPlayerUtil.getInstance().playSound(14, 2);
        } else {
            AudioPlayerUtil.getInstance().stopSound(14);
        }
        setBackgroundColor(isFocus ? Color.parseColor("#666666") : mDefaultColor);
    }
}
